package com.topvision.controller.hes;

import com.topvision.annotation.IgnoreAuth;
import com.topvision.dto.Video;
import com.topvision.model.hes.Videostream;
import com.topvision.model.zwan.CompanyPro;
import com.topvision.model.zwan.Companydevice;
import com.topvision.model.zwan.SessionFlow;
import com.topvision.service.hes.VideostreamService;
import com.topvision.service.zwan.CompanyProService;
import com.topvision.service.zwan.CompanydeviceService;
import com.topvision.service.zwan.SessionFlowService;
import com.topvision.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "远程协助视频接口", description = "远程协助视频接口，暂未做请求token验证，安全考虑建议token鉴权，需要请求api的登录接口")
@RequestMapping("video")
@CrossOrigin
public class VideoController {

    @Autowired
    private VideostreamService videostreamService;

    @Autowired
    private CompanydeviceService companydeviceService;

    @Autowired
    private CompanyProService companyProService;

    @Autowired
    private SessionFlowService sessionFlowService;

    @IgnoreAuth
    @RequestMapping(value = "/findListByParam", method = RequestMethod.POST)
    @ApiResponses(value = {@ApiResponse(code = 200, message = "视频信息", response = R.class)})
    @ApiOperation(value = "用户远程协助视频查看接口", produces = MediaType.APPLICATION_JSON_VALUE, notes = "用户远程协助视频查看接口，根据订单号，或者用户名多条件查询", response = R.class)
    public R findListByParam(@RequestBody Video video) {
        Map<String, Object> params = new HashMap<>();
        if (video.getOrderId() != null) {
            params.put("orderId", video.getOrderId());
        }
        List<Videostream> videostreamList = videostreamService.queryByParam(params);
        return R.success().put("videoList", videostreamList);
    }


    @IgnoreAuth
    @RequestMapping(value = "/resolutionLimit/{companyid}",method = RequestMethod.GET)
    @ApiResponses(value = {@ApiResponse(code = 200, message = "视频信息", response = R.class)})
    @ApiOperation(value = "分辨率接口信息", produces = MediaType.APPLICATION_JSON_VALUE, notes = "用户远程协助视频查看接口，根据订单号，或者用户名多条件查询", response = R.class)
    public R resolutionLimit(@PathVariable String companyid) {
        Map<String, Object> params = new HashMap<>();
        params.put("companyid", companyid);
        CompanyPro companyPro = companyProService.queryObjectByMap(params);
        return R.success().put("companyPro", companyPro);
    }


    /**
     * 流量新增
     */
    @IgnoreAuth
    @RequestMapping(value ="/addFlow",method = RequestMethod.POST)
    @ApiResponses(value = {@ApiResponse(code = 200, message = "流量统计", response = R.class)})
    @ApiOperation(value = "流量统计信息接入", produces = MediaType.APPLICATION_JSON_VALUE, notes = "统计各端各设备的流量功能", response = R.class)
    public R save(@RequestBody SessionFlow sessionFlow){
        sessionFlowService.save(sessionFlow);
        return R.success();
    }


}
